package com.game.element.cooldown
{
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.utils.Dictionary;
	import flash.utils.getTimer;
	
	public class CoolDownSprite extends Sprite implements ICoolDown{
		private var w1:int = 36;
		private var h1:int = 36;
		private var bitmap:Bitmap = new Bitmap;
		private var lastDrawTime:Number =0;
		private var _coolDown:Number =-1;
		
		public function CoolDownSprite() {
			super();
			addChild(bitmap);
		}
		
		public function get length():int{
			return 36
		}
		
		public function setDraw(angle:int):void{
			angle = angle%360;
			bitmap.bitmapData = SpriteUtil.getCoolDownBitMap(angle,length);
		}
		
		public function step():void{
			if(_coolDown == -1){
				return;
			}
			var passTime:Number = getTimer() - lastDrawTime;
			if(passTime > _coolDown){
				_coolDown = -1;
				setDraw(0);
				return;
			}
			setDraw(passTime/(_coolDown)*360);
		}
		
		/**
		 * 冷却秒数
		 */
		public function set coolDown(coolDown:Number):void{
			_coolDown = coolDown;
			lastDrawTime = getTimer();
		}
		
	}
}